unit MatrixOperations;

interface

type

  DoubleMatrix = array of array of Double;

  TMatrixOperations = class

    class procedure MultiplyMatrix(M1 : DoubleMatrix; M2: array of Double ; var Result: array of Double);
    class procedure KronMatrix(M1, M2 : array of Double; var Result : DoubleMatrix);

    class function TransposeMatrix (M1 : DoubleMatrix) : DoubleMatrix;

    class function MultiplyMatrix2 ( M1 , M2 : DoubleMatrix ) : DoubleMatrix ;

  end;

implementation



{ TMatrixOperations }

class procedure TMatrixOperations.KronMatrix(M1, M2: array of Double;
  var Result: DoubleMatrix);
var
  i, j : Integer;
begin
  for i := 0 to Length(M1)-1 do
    begin
      for j := 0 to Length(M2)-1 do
        begin
          Result[i][j] := M1[i]*M2[j];
        end;
    end;

end;

class procedure TMatrixOperations.MultiplyMatrix(M1 : DoubleMatrix; M2: array of Double ; var Result: array of Double);
var
  i, j : Integer;
  temp : Double;

begin

  // linha M1
  for i := 0 to Length(M1)-1 do
    begin
      temp := 0;
      // coluna M1 e linha M2
      for j := 0 to Length(M2)-1 do
        begin
          temp := temp + M1[i][j]*M2[j];
        end;
      Result[i] := temp;
    end;


end;

class function TMatrixOperations.MultiplyMatrix2(M1,
  M2: DoubleMatrix): DoubleMatrix;
var
  i , j , k   : Integer ;
  tmp    : Double ;
begin

  for i := 0 to Length ( M1 ) - 1 do
  begin
    tmp := 0.0 ;
    for k := 0 to Length ( M2 ) - 1 do
    begin
      for j := 0 to Length ( M2[k] ) - 1 do
      begin
        //
      end;
    end;
  end;

end;

class function TMatrixOperations.TransposeMatrix(
  M1: DoubleMatrix): DoubleMatrix;
var
  i, j : Integer;
begin
  SetLength(Result, Length(M1[0]), Length(M1));

  for i := 0 to Length(M1)-1 do
    begin
      for j := 0 to Length(M1[0])-1 do
        begin
          Result[j][i] := M1[i][j];
        end;
    end;

end;

end.
